/*
 * Created on Jun 22, 2005
 */
package org.vectrics.event;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.vectrics.SystemException;
import org.vectrics.common.db.Auditable;
import org.vectrics.common.db.OwnedObject;
import org.vectrics.common.db.RecordObject;
import org.vectrics.common.util.DateSync;
import org.vectrics.domain.Domain;
import org.vectrics.user.Person;


/**
 * @author MMoore
 */
public class Event implements RecordObject, Auditable, OwnedObject {
	public static String STATUS_UNPROCESSED = "unproc";
	public static String STATUS_PROCESSED = "proc";
	public static String STATUS_ERROR = "error";
	public static String STATUS_NOT_PROCESSED = "not.proc";
	
	private Long id = null;
	private String description = null;
	private Date eventTime = DateSync.getCurrentTime();
	private Date processedTime = null;
	private EventType eventType = null;
	private List attachments = new ArrayList();
	private Long retryCount = new Long(0);
	private String status = Event.STATUS_UNPROCESSED;
	private String error = null;
	private Person createdBy = null;
	private Date createdDate = null;
	private Person lastModifiedBy = null;
	private Date lastModifiedDate = null;
	private Domain domain = null;
 
	
	/**
	 * 
	 */
	public Event() {
		super();
	}
	
	
	/**
	 * @return Returns the description.
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description The description to set.
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return Returns the eventTime.
	 */
	public Date getEventTime() {
		return eventTime;
	}
	/**
	 * @param eventTime The eventTime to set.
	 */
	public void setEventTime(Date eventTime) {
		this.eventTime = eventTime;
	}
	/**
	 * @return Returns the eventType.
	 */
	public EventType getEventType() {
		return eventType;
	}
	/**
	 * @param eventType The eventType to set.
	 */
	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}
	/**
	 * @return Returns the id.
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id The id to set.
	 */
	public void setId(Long id) {
		this.id = id;
	}
	
	/**
	 * @return Returns the processedTime.
	 */
	public Date getProcessedTime() {
		return processedTime;
	}
	/**
	 * @param processedTime The processedTime to set.
	 */
	public void setProcessedTime(Date processedTime) {
		this.processedTime = processedTime;
	}

	
	public EventAttachment addAttachment(RecordObject object, String objectType,
			String description) {
		//if (object.getId() == null)
		//	throw new SystemException("Can't attach object to event that has a null id, may need to save attached object again.");
		
		EventAttachment attachment = new EventAttachment();
		attachment.setDescription(description);
		attachment.setEvent(this);
		if (object.getId() == null) {
			attachment.setObject(object);
		} else {
			attachment.setObjectId(object.getId().toString());
		}
		attachment.setObjectType(objectType);
		this.attachments.add(attachment);
		return(attachment);
	}
	
	/**
	 * @return Returns the attachments.
	 */
	public List getAttachments() {
		return attachments;
	}

	/**
	 * @param attachments The attachments to set.
	 */
	public void setAttachments(List attachments) {
		this.attachments = attachments;
	}
	
	/**
	 * @return Returns the retryCount.
	 */
	public Long getRetryCount() {
		return retryCount;
	}
	/**
	 * @param retryCount The retryCount to set.
	 */
	public void setRetryCount(Long retryCount) {
		this.retryCount = retryCount;
	}
	
	
	/**
	 * @return Returns the error.
	 */
	public String getError() {
		return error;
	}
	/**
	 * @param error The error to set.
	 */
	public void setError(String error) {
		this.error = error;
	}
	/**
	 * @return Returns the status.
	 */
	public String getStatus() {
		return status;
	}
	/**
	 * @param status The status to set.
	 */
	public void setStatus(String status) {
		this.status = status;
	}


	/**
	 * @return Returns the createdBy.
	 */
	public Person getCreatedBy() {
		return createdBy;
	}


	/**
	 * @param createdBy The createdBy to set.
	 */
	public void setCreatedBy(Person createdBy) {
		this.createdBy = createdBy;
	}


	/**
	 * @return Returns the createdDate.
	 */
	public Date getCreatedDate() {
		return createdDate;
	}


	/**
	 * @param createdDate The createdDate to set.
	 */
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}


	/**
	 * @return Returns the lastModifiedBy.
	 */
	public Person getLastModifiedBy() {
		return lastModifiedBy;
	}


	/**
	 * @param lastModifiedBy The lastModifiedBy to set.
	 */
	public void setLastModifiedBy(Person lastModifiedBy) {
		this.lastModifiedBy = lastModifiedBy;
	}


	/**
	 * @return Returns the lastModifiedDate.
	 */
	public Date getLastModifiedDate() {
		return lastModifiedDate;
	}


	/**
	 * @param lastModifiedDate The lastModifiedDate to set.
	 */
	public void setLastModifiedDate(Date lastModifiedDate) {
		this.lastModifiedDate = lastModifiedDate;
	}
	
	public boolean logEntityChanges() {
		return(false);
	}


	/**
	 * @return Returns the domain.
	 */
	public Domain getDomain() {
		return domain;
	}


	/**
	 * @param domain The domain to set.
	 */
	public void setDomain(Domain domain) {
		this.domain = domain;
	}
	
}
